package Demo1;

public class T7 {
//    设置成守护线程
    public static void main(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 20; i++) {
                    System.out.println(Thread.currentThread().getName()+"---"+i);
                }
            }
        },"A :");
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 2000; i++) {
                    System.out.println(Thread.currentThread().getName()+"---"+i);
                }
            }
        },"B :");
        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 200; i++) {
                    System.out.println(Thread.currentThread().getName()+"---"+i);
                }
            }
        },"C :");

        thread2.setDaemon(true);//将 thread2 设置为守护线程 当thread1 结束后 thread2 也就结束了
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
